package com.hx.petsever.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hx.petsever.entity.Address;
import com.hx.petsever.entity.Cart;
import com.hx.petsever.entity.CartVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {
    @Select("SELECT c.goodid , a.name , a.price ,a.imageid , c.num  FROM goods a , user b , cart c WHERE c.userid = #{id} AND  c.goodid = a.id AND b.phone = #{id} ")
    List<CartVo> getCart(@Param("id") String id);

    @Insert("INSERT INTO cart SET userid = #{userid} , goodid = #{goodid} , num = #{num}")
    void addCart(@Param("userid") String userid , @Param("goodid") Integer goodid , @Param("num") Integer num);

    @Select("SELECT * FROM cart WHERE userid = #{userid} AND goodid = #{goodid}")
    Cart havaCart(@Param("userid") String userid , @Param("goodid") Integer goodid);

    @Update("UPDATE cart SET  num = #{num} WHERE userid = #{userid} AND goodid = #{goodid}")
    void upCart(@Param("userid") String userid , @Param("goodid") Integer goodid , @Param("num") Integer num);

    @Delete("DELETE FROM  cart WHERE  userid = #{userid} AND  goodid = #{goodid} AND  num = #{num}")
    void delete(@Param("userid") String userid , @Param("goodid") Integer goodid , @Param("num") Integer num);

}
